﻿Imports Mystery

''' <summary>
''' create controls for adding a content
''' </summary>
''' <remarks></remarks>
Public Class ContentControlAddAttribute
    Inherits MysteryDefaultClassAttribute

    Public Property implementing_type As Type

    Private _control_activator As IActivator

    Public Overrides Sub setUp()

        If implementing_type IsNot Nothing Then
            implementing_type.GetInterfaceMap(GetType(IContentCreatorControl)) 'crash if not right
        Else
            implementing_type = GetType(ContentAdd)
        End If

        _control_activator = getGlobalObject(Of FastActivator).getActivator(implementing_type)
    End Sub

    ''' <summary>
    ''' the returned type it is garties to be also IContentCreator
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function createControl(content As IContent) As UserControl
        Dim content_add As IContentCreatorControl = _control_activator.createInstance()
        content_add.setUp(Me.used_in, content)
        Return content_add
    End Function

End Class

''' <summary>
''' enable the content to be addeable from the interface
''' </summary>
''' <remarks></remarks>
Public Class ContentButtonAddAttribute
    Inherits MysteryClassAttribute

    Public Sub New()

    End Sub

    Public Property implementing_type As Type

    Private _button_activator As IActivator
    Dim generic As Type = GetType(ContentAddButton(Of ))

    Public Overrides Sub setUp()
        If implementing_type IsNot Nothing Then
            implementing_type.GetInterfaceMap(GetType(IButton))
        Else
            implementing_type = Generic.MakeGenericType(used_in)
        End If

        _button_activator = getGlobalObject(Of FastActivator).getActivator(implementing_type)
    End Sub

    Public Function createButton() As IButton
        Dim b As IButton = _button_activator.createInstance()
        Return b
    End Function

End Class
